﻿Imports System.Data.OleDb
Public Class LikeDish
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        img_smiley.Visible = False

        Dim oleDbConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("JamaicanConnectionString").ConnectionString)
        Dim sql = "SELECT * FROM MemberLikes WHERE Reader = @j1 AND DishID = @j2"
        Dim oleDbCmd As New OleDbCommand(sql, oleDbConn)
        oleDbConn.Open()

        oleDbCmd.Parameters.AddWithValue("@j1", User.Identity.Name)
        oleDbCmd.Parameters.AddWithValue("@j2", Request.Params("ID"))

        Dim dr As OleDbDataReader = oleDbCmd.ExecuteReader()

        If dr.HasRows Then
            img_smiley.Visible = True
            btn_like.Visible = False
        Else
            img_smiley.Visible = False
            btn_like.Visible = True

        End If

        oleDbConn.Close()

    End Sub

    Protected Sub btn_like_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_like.Click
        img_smiley.Visible = True
        btn_like.Visible = False

        Dim oleDbConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("JamaicanConnectionString").ConnectionString)
        Dim sql = "INSERT INTO MemberLikes (DishID,Reader) VALUES (@j1,@j2)"
        Dim oleDbCmd As New OleDbCommand(sql, oleDbConn)
        oleDbConn.Open()
        oleDbCmd.Parameters.AddWithValue("@j1", Request.Params("ID"))
        oleDbCmd.Parameters.AddWithValue("@j2", User.Identity.Name)
        oleDbCmd.ExecuteNonQuery()
        oleDbConn.Close()
        oleDbCmd.Dispose()
        oleDbConn.Dispose()

    End Sub
End Class